﻿using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class UserOperate : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IBeginDragHandler, IEndDragHandler
{
    private bool m_bBtnDown;
    public bool m_bIsKeepSize;

    public enum btnState
    {
        btnStateDown,
        btnStatePressed,
        btnStateUp,
    }

    public enum dragState
    {
        dragStateBegin,
        dragStateDraging,
        dragStateEnd,
    }

    void Start()
    {
        //GameData.logger("222", 1);
    }

    void Update()
    {
        if (m_bBtnDown)
        {
            //GameData.logger(" on Pointing !", 1);
            EventDispatcher.onBtnEvent(this.gameObject, btnState.btnStatePressed);
        }
    }
    
    public void OnPointerDown(PointerEventData eventData)
    {
        m_bBtnDown = true;
        //GameData.logger(" on Point Down !", 1);
        EventDispatcher.onBtnEvent(this.gameObject, btnState.btnStateDown);
        if (!m_bIsKeepSize) gameObject.transform.localScale = GameData.ii.vBtnClicked;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        m_bBtnDown = false;
        //GameData.logger(" on Point Up !", 1);
        EventDispatcher.onBtnEvent(this.gameObject, btnState.btnStateUp);
        if(!m_bIsKeepSize) gameObject.transform.localScale = GameData.ii.vBtnNormal;
    }

    public void OnDrag(PointerEventData eventData)
    {
        //GameData.logger(" on Draging !", 1);
        EventDispatcher.onDropEvent(this.gameObject, dragState.dragStateDraging, eventData);
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        //GameData.logger(" on Drag Begin !", 1);
        EventDispatcher.onDropEvent(this.gameObject, dragState.dragStateBegin, eventData);
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        //GameData.logger(" on Drag Ned !", 1);
        EventDispatcher.onDropEvent(this.gameObject, dragState.dragStateEnd, eventData);
    }
}
